﻿#pragma once

#include "../MirEnvir/Envir.h"
#include "../../Shared/Data/ItemData.h"
#include "CharacterInfo.h"
#include "../../Shared/Enums.h"
#include "../../Shared/Data/ClientData.h"
#include <string>

using namespace Server::MirEnvir;

namespace Server::MirDatabase
{
    class AuctionInfo
    {
    public:
        virtual ~AuctionInfo()
        {
            delete Item;
            delete SellerInfo;
            delete CurrentBuyerInfo;
        }

    protected:
        static Server::MirEnvir::Envir *getEnvir();

    public:
        unsigned long long AuctionID = 0;

        UserItem *Item;
        DateTime ConsignmentDate;
        unsigned int Price = 0, CurrentBid = 0;

        int SellerIndex = 0, CurrentBuyerIndex = 0;
        CharacterInfo *SellerInfo, *CurrentBuyerInfo;

        bool Expired = false, Sold = false;

        MarketItemType ItemType = static_cast<MarketItemType>(0);

        AuctionInfo();


        AuctionInfo(CharacterInfo *info, UserItem *item, unsigned int price, MarketItemType itemType);

        AuctionInfo(BinaryReader *reader, int version, int customversion);

        void Save(BinaryWriter *writer);

    private:
        std::string GetSellerLabel(bool userMatch);

    public:
        ClientAuction *CreateClientAuction(bool userMatch);
    };
}
